import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Microsoft
 * Date: 2023-03-25
 * Time: 18:47
 */
public class Test2 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] array = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = scan.nextInt();
        }
        int max = array[0];
        int tmp = array[0];
        for (int i = 0; i < array.length; i++) {
            if (array[i] > 0) {
                tmp += array[i];
            }
            if (array[i] < 0) {
                max = Math.max(max,tmp);
            }
        }
        System.out.println(max);
    }
}
